﻿// Decompiled with JetBrains decompiler
// Type: Microsoft.InfoCards.DisplayToken
// Assembly: infocard, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// MVID: 8E14765A-6610-409A-BA36-099A0642905D
// Assembly location: E:\git\ALLIDA\windll\infocard.exe

using Microsoft.InfoCards.Diagnostics;
using System;
using System.Collections.Generic;
using System.IO;

namespace Microsoft.InfoCards
{
  internal class DisplayToken
  {
    private string m_displayString;
    private string m_mimeType;
    private List<DisplayClaim> m_displayList;
    private DisplayClaimType m_displayType;

    public IEnumerable<DisplayClaim> ClaimList
    {
      get
      {
        return (IEnumerable<DisplayClaim>) this.m_displayList;
      }
    }

    public DisplayToken()
    {
      this.m_displayType = DisplayClaimType.NoDisplayToken;
    }

    public DisplayToken(string displayString, string mimeType)
    {
      this.m_displayString = displayString;
      this.m_mimeType = mimeType;
      this.m_displayType = DisplayClaimType.DisplayClaimString;
    }

    public DisplayToken(List<DisplayClaim> claimList)
    {
      this.m_displayList = claimList;
      this.m_displayType = DisplayClaimType.DisplayClaimList;
    }

    public void Serialize(BinaryWriter writer)
    {
      writer.Write((byte) this.m_displayType);
      switch (this.m_displayType)
      {
        case DisplayClaimType.NoDisplayToken:
          break;
        case DisplayClaimType.DisplayClaimString:
          Utility.SerializeString(writer, this.m_displayString);
          Utility.SerializeString(writer, this.m_mimeType);
          break;
        case DisplayClaimType.DisplayClaimList:
          writer.Write((uint) this.m_displayList.Count);
          using (List<DisplayClaim>.Enumerator enumerator = this.m_displayList.GetEnumerator())
          {
            while (enumerator.MoveNext())
              enumerator.Current.Serialize(writer);
            break;
          }
        default:
          InfoCardTrace.ThrowInvalidArgumentConditional(true, "ClaimType");
          break;
      }
    }

    public void Deserialize(BinaryReader reader)
    {
      this.m_displayType = (DisplayClaimType) reader.ReadByte();
      switch (this.m_displayType)
      {
        case DisplayClaimType.NoDisplayToken:
          break;
        case DisplayClaimType.DisplayClaimString:
          this.m_displayString = Utility.DeserializeString(reader);
          this.m_mimeType = Utility.DeserializeString(reader);
          break;
        case DisplayClaimType.DisplayClaimList:
          this.m_displayList.Clear();
          uint num = reader.ReadUInt32();
          for (uint index = 0; index < num; ++index)
            this.m_displayList.Add(new DisplayClaim(reader));
          break;
        default:
          throw InfoCardTrace.ThrowHelperError((Exception) new InvalidOperationException(SR.GetString("InvalidDisplayClaimType")));
      }
    }
  }
}
